// getElementByClassName 获取一个试试更新的 HTMLCollection
const toggles = document.getElementsByClassName("toggle");
// querySelectorAll 获取一个 NodeList
// const toggles = document.querySelectorAll(".toggle");
const good = document.getElementById("good");
const cheap = document.getElementById("cheap");
const fast = document.getElementById("fast");

// HTMLCollection
Array.prototype.forEach.call(toggles, function (toggle) {
  toggle.addEventListener("change", (e) => doTheTrick(e.target));
});

// NodeList
// toggles.forEach((toggle) => {
//   toggle.addEventListener("change", (e) => doTheTrick(e.target));
// })

function doTheTrick(thisToggle) {
  if (good.checked && cheap.checked && fast.checked) {
    console.log(true);
    if (good === thisToggle) {
      fast.checked = false;
    }
    if (cheap === thisToggle) {
      good.checked = false;
    }
    if (fast === thisToggle) {
      cheap.checked = false;
    }
  }
}

